#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <QCamera>
#include <QVideoWidget>

//预览窗口widgetCamera
// 1. 添加QWidget并命名widgetCamera
// 2. 右键提升为QVideoWidget

QCamera m_camera;

void MainWindow::on_pushButton_uvc_on_clicked()
{
    m_camera.setCaptureMode(QCamera::CaptureVideo); //设置捕捉模式为视频
    m_camera.setViewfinder(ui->widgetCamera);       //设置 摄像头画面的显示位置

    m_camera.start(); //开启摄像头
}

void MainWindow::on_pushButton_uvc_snap_clicked()
{
    //开启状态下抓拍
    if (m_camera.state() == QCamera::ActiveState)
    {
        QPixmap pixmap = ui->widgetCamera->grab(); //将widget内容保存为pixmap图像信息
        pixmap.save("Snap.bmp");               //保存为Snap.bmp
    }
}

void MainWindow::on_pushButton_uvc_off_clicked()
{
    m_camera.stop(); //关闭摄像头
}

